package com.ruicar.afs.cloud.product.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.product.condition.ProductAtomCondition;
import com.ruicar.afs.cloud.product.entity.ProductAtom;
import com.ruicar.afs.cloud.product.enums.ProductTemplateCategoryEnum;
import com.ruicar.afs.cloud.product.mapper.ProductAtomMapper;
import com.ruicar.afs.cloud.product.service.ProductAtomService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author changyu.gui
 * @version 1.0
 * @describe 产品原子信息
 * @date 2020/4/27 17:26
 */
@Service("productAtomService")
public class ProductAtomServiceImpl extends ServiceImpl<ProductAtomMapper, ProductAtom> implements ProductAtomService {

    public List<ProductAtom> getListProductAtom(ProductAtomCondition productAtomCondition) {
        String[] range = ProductTemplateCategoryEnum.getRange(productAtomCondition.getTemplateCategory());
        productAtomCondition.setRange(range);
        return baseMapper.getListProductAtom(productAtomCondition);
    }

    public Boolean updateAtomIsReference(ProductAtom productAtom, String status) {
        if (productAtom == null) return false;
        if (!status.equals(productAtom.getAtomIsReference())) {
            productAtom.setAtomIsReference(status);
            this.updateById(productAtom);
        }
        return true;
    }

    public IPage<List<ProductAtom>> getProductTemplateDetails(Page page, ProductAtomCondition productAtomCondition) {
        return baseMapper.getProductTemplateDetails(page, productAtomCondition);
    }


}
